import {defineMutation, useMutation} from "@pinia/colada";
import {deleteCar} from "../api/car.ts";
import {ElMessage} from "element-plus"
import {ref} from "vue";

export const useDeleteCar = defineMutation(() => {
  const needDeleteCarId = ref<number>()
  const {mutate, ...mutation} = useMutation<boolean, number>({
    mutation: (carId: number) => deleteCar(carId),
    onSuccess: () => {
        ElMessage.success("删除成功")
    }
  });

  return {
    deleteCarFn: (carId: number) => {
      needDeleteCarId.value = carId
      mutate(carId)
    },
    needDeleteCarId,
    mutation
  }
})